﻿using DBLibrary.DataBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace DBLibrary.Model.pojo
{
    [Serializable]
    public class HistoryData : BaseClone<HistoryData>    //历史数据表
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };
        private int _SensorId;                      //[系统序号]
        private float _curValue;                    //[当前值]
        private DateTime _Time;                     //[时间]
        private DateTime _Time2;                     //[时间2]
        private int _hotBackup1;                   //热备状态1
        private int _hotBackup2;                   //热备状态2
        private int _isUpload;                      //[上传否]
        private int _isUpload2;                     //[上传否2]
        private int _isUpload3;                     //[上传否3]
        private int _isUpload4;                     //[上传否4]
        private int status;
        private string location;
        private string type;
        private string portStr;
        private string  displayValue;
        private string displayStatus;
        private int isCaliberate; 
        public HistoryData(DateTime time, float value, int status) { 
            Time= time;
            CurValue = value;
            Status = status;
        }
        public HistoryData() { }
        public int SensorId {
            get => _SensorId;
            set
            {
                _SensorId = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("SensorId"));
                }
            }
        }
        public float CurValue {
            get => _curValue;
            set
            {
                _curValue = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("CurValue"));
                }
            }
        }
        public DateTime Time {
            get => _Time;
            set
            {
                _Time = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Time"));
                }
            }
        }

        public DateTime Time2
        {
            get => _Time2;
            set
            {
                _Time2 = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Time2"));
                }
            }
        }
        public int IsUpload {
            get => _isUpload;
            set
            {
                _isUpload = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsUpload"));
                }
            }
        }
        public int IsUpload2 {
            get => _isUpload2;
            set
            {
                _isUpload2 = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsUpload2"));
                }
            }
        }
        public int IsUpload3 {
            get => _isUpload3;
            set
            {
                _isUpload3 = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsUpload3"));
                }
            }
        }
        public int IsUpload4 {
            get => _isUpload4;
            set
            {
                 _isUpload4 = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsUpload4"));
                }
            }
        }
        public int HotBackup1 {
            get => _hotBackup1;
            set
            {
                _hotBackup1 = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("HotBackup1"));
                }
            }
        }
        public int HotBackup2 {
            get => _hotBackup2;
            set
            {
                _hotBackup2 = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("HotBackup2"));
                }
            }
        }

        public int Status { get => status; set => status = value; }
        public string Location { get => location; set => location = value; }
        public string Type { get => type; set => type = value; }
        public string PortStr { get => portStr; set => portStr = value; }
        public string DisplayValue {
            get {
                if (_curValue < -99)
                    return "--";
                else
                    return _curValue.ToString();
            } 
            set => displayValue = value; }

        public string DisplayStatus {
            get {
                switch (status) {
                    case 200:
                    case 100:
                        return "正常";
                    case 202:
                    case 102:
                        return "报警";
                    case 204:
                    case 104:
                        return "断电";
                    case 206:
                    case 106:
                        return "断电结束";
                    case 208:
                    case 108:
                        return "报警结束";
                    default:
                        return "正常";
                }
            }  
        }
        public int IsCaliberate {
            get {
                if (status < 200 && status>0)
                    return 1;
                else 
                    return 0;
            }
        }
    }
}
